<template>
  <div id="centerRight1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span style="color:#5cd9e8">
          <icon name="chart-line"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">各城市新增确诊人数Top100</span>
        </div>
      </div>
      <div class="d-flex jc-center body-box">
        <dv-scroll-board :config="config" style="width:5.375rem;height:4.28rem" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      config: {
        header: ["州", "城市", "新增百分比"],
        data: [],
        rowNum: 7, //表格行数
        headerHeight: 35,
        headerBGC: "#0f1325", //表头
        oddRowBGC: "#0f1325", //奇数行
        evenRowBGC: "#171c33", //偶数行
        index: true,
        columnWidth: [50],
        align: ["center"]
      }
    };
  },
  components: {},
  mounted() {
    this.getdata(100);
  },
  methods: {
    async getdata(n){
      let self = this;
      this.$http.get('http://116.196.92.193:8090/data/getRight1', {
        params: {
        }
      }).then(function (response) {
        //console.info(response);
        var obj = response.data.data;
        var keyArr = [],valArr = [];
        for (var key in obj) {
          keyArr.push(key);
          valArr.push(obj[key]);
        }
        for (var i = 0, len = valArr.length; i < len; i++) {
          for (var j = 0; j < len - i; j++) {
            var keyTemp, valTemp;
            if (valArr[j] < valArr[j + 1]) {
              valTemp = valArr[j];
              valArr[j] = valArr[j + 1];
              valArr[j+1] = valTemp;
              keyTemp = keyArr[j];
              keyArr[j] = keyArr[j + 1];
              keyArr[j+1] = keyTemp;
            }
          }
        }
        var newobj=[];
        for(i=0;i<n;i++){
          newobj.push([keyArr[i].split('-')[1], keyArr[i].split('-')[0]=="Unknown"?keyArr[i].split('-')[1]:keyArr[i].split('-')[0],
            Math.round(valArr[i])<=0?"<span  class='colorGrass'>0%</span>": "<span  class='colorRed'>↑"+Math.round(valArr[i])+"%</span>"]);
        }
        //console.info(newobj);
        self.config.data=newobj;
        self.config = { ...self.config };
      }).catch(function (error) {
        console.log(error);
      });
    },
  }
};
</script>

<style lang="scss">
#centerRight1 {
  padding: 0.2rem;
  height: 5.125rem;
  min-width: 3.75rem;
  border-radius: 0.0625rem;
  .bg-color-black {
    height: 4.8125rem;
    border-radius: 0.125rem;
  }
  .text {
    color: #c3cbde;
  }
  .body-box {
    border-radius: 0.125rem;
    overflow: hidden;
  }
}
</style>
